package com.dhp.model.enums;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 代码沙箱执行枚举类
 */
public enum CodeSandBoxExecuteEnum {
    EXE_SUCCESS("执行成功" , 1),
    COMPILE_FAILED("编译失败" , 2),
    EXE_FAILED("执行失败" , 3);


    private final String label;
    private final Integer value;

    CodeSandBoxExecuteEnum(String label , Integer value){
        this.label = label;
        this.value = value;
    }

    public String getLabel() {
        return label;
    }

    public Integer getValue() {
        return value;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<Integer> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static CodeSandBoxExecuteEnum getEnumByValue(Integer value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (CodeSandBoxExecuteEnum anEnum : CodeSandBoxExecuteEnum.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }
}
